package com.xm.dao.impl;

import com.xm.dao.NewsDao;
import com.xm.po.News;
import com.xm.util.DButil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @date 2020-08-07-15:25
 * @description 新闻数据操作接口实现类
 */
public class NewsDaoImpl implements NewsDao {
    @Override
    public List<News> getAll() {
        List<News> list = new ArrayList<>();
        Connection conn = DButil.getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "select * from news order by createTime desc limit 8";
        try {
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            list = (List<News>) DButil.getRsData(News.class,rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DButil.close(rs,ps,conn);
        }
        return list;
    }

    @Override
    public boolean add(News news) {
        return false;
    }

    @Override
    public boolean update(News news) {
        return DButil.update(news);
    }

    @Override
    public boolean deleteById(String id) {
        return DButil.delete(News.class,id);
    }
}
